/****************************************************************
 * I am the AC 130 vs Pirate game. I allow the user to control an 
 * AC130 gunship in the hunt for Modern day pirates. The player  
 * will be allowed to roam free across a section of ocean/coastline.  
 * In the water there will be four types of vessels: Merchant  
 * ships that the player must protect, Pirate ships that the player  
 * must identify and destroy, Fishing boats that look like Pirate  
 * ships that the player must not destroy, and Friendly Navy ships  
 * that can capture pirates for extra points. Time permitting there  
 * may also be ground targets to attack. 
 *
 * Key elements of this project will be the Player/AC130, the Ships,  
 * the ShipAI system, the collision grid, the debris controller, the  
 * Ground/Water, Clouds, and scoring system. This project will make  
 * use of an external text file to store useful game parameters,  
 * thus allowing us to play balance the game without recompiling  
 * the executable. 
 *****************************************************************
 * I am the Crash Bin class. I act as an inter object reference system. 
 * Each object in the world is required to register its current position
 * with me. Once registered an index to the current object can be found
 * within a bounding area. Other object can then reference this bounding 
 * area to find the indexes of the registered objects. This method is 
 * preferable to the O(n*m) algorithem that has to be run to compare
 * all elements of one array to another.
 *****************************************************************/

#include <allegro.h>
#include "point.h"
#include "GameData.h"

#ifndef __CRASH_BIN_H__
#define __CRASH_BIN_H__

#define BINMAX 256
#define BINHGT 32

enum tpBinType {btNull, btPlayer, btBuilding, btBullet, btBoat, btPeople};

class CrashBin{
public:
	GameData *gd;
	// grid data
	int gridWidth;
	int gridHeight;
	int nodeWidth;
	int nodeHeight;
	int * gridRef; // references bin
	int * gridAge;// age of index;
	int curAge;	// current age

	// bin data
	int maxBin;	// top used bin
	tpBinType binType[BINMAX][BINHGT];
	int binIndex[BINMAX][BINHGT];
	int binTop[BINMAX];// top element in the indexed bin

public:
	CrashBin();
	~CrashBin();
	void Init(GameData * exgd);
		// sets the gridRef and gridAge to appropriare dimentions
	void SetLevel(int width, int height);
		// called at te start of the register process;
		// to empty old registry;
	void ClearRegister();
		// register an individual element
	void Register(tpBinType type, int index, float xval, float yval);

		// count the registeered elements in the specified area
	int CountArea(float xval, float yval, float radius);
		//pull the registered elements from
	tpBinType FetchType(int index, float xval, float yval, float radius);
	int FetchIndex(int index, float xval, float yval, float radius);

private:
	// conversion functions
	int GetIndex(float x, float y);


};


#endif